<?php
namespace app\index\validate;
use think\Validate;

class User extends Validate{
    
 /*    protected $rule=[
        'nickname'=>'require|min:5|token',
        'email'=>'require|email',
        'birthday'=>'dateFormat:Y-m-d',
    ];
     */
    
/*  //2   
    // 验证规则
    protected $rule = [
        'nickname' => ['require', 'min'=>1 , 'token' ],
        'email'    => ['require', 'email'],
       'birthday' => ['dateFormat'=>'Y-m-d'],
    ];
    
     */
/*     
    //3
    // 验证规则
    protected $rule = [
        'nickname|昵称' => 'require|min:1',
        //'email|邮箱'    => 'require|email',
        'birthday|生日' => 'dateFormat:Y-m-d',
    ]; */
    
/*   //  
    protected $rule = [
        ['nickname', 'require|min:1', '昵称必须|昵称不能短于1个字符'],
        ['email', 'email', '邮箱格式错误'],
        ['birthday', 'dateFormat:Y-m-d', '生日格式错误'],
    ];
    
     */
    
    // 验证规则
    protected $rule = [
        ['email', 'require|email', '邮箱格式错误'],
        ['name','require|min:2', '昵称必须|昵称不能短于2个字符'],
     //   ['nickname', 'require|min:5', '昵称必须|昵称不能短于5个字符'],
       // ['email', 'checkMail:thinkphp.cn', '邮箱格式错误'],
      //  ['birthday', 'dateFormat:Y-m-d', '生日格式错误'],
    ];
    
    protected $message = [
        'name.require'  =>  '用户名必须',
    ];
    
    
   // array('type_name', 'unique', '商品类型名称已经存在！',0,'unique'),
    
    
/*     
    // 验证邮箱格式 是否符合指定的域名
    protected function checkMail($value, $rule)
    {
     //   return 1 === preg_match('/^\w+([-+.]\w+)*@' . $rule . '$/', $value);
        
        
        $result = preg_match('/^\w+([-+.]\w+)*@' . $rule . '$/', $value);
        if (!$result) {
            return '邮箱只能是' . $rule . '域名';
        } else {
            return true;
        }
        
    }
     */
    
}